package org.com.Rabbit;

import Entity.OrderVoucher;
import lombok.extern.slf4j.Slf4j;
import org.com.Service.IOrderVoucherService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.Map;

@Slf4j
@Component
public class VoucherListen {
    @Autowired
    private IOrderVoucherService orderVoucherService;
    @RabbitListener(bindings =
    @QueueBinding(value = @Queue("voucher.queue"),
            exchange = @Exchange(value = "order.exchange", type = ExchangeTypes.TOPIC),
            key = "voucher订单创建")
    )
    public void listen(Map<String, Object> map) {
        log.info("开始保存订单");
        OrderVoucher orderVoucher = new OrderVoucher();
        orderVoucher.setUserId((Integer) map.get("userid"));

        log.info("++++++++++++++++++userid"+map.get("userid"));
        orderVoucher.setVoucherId((Integer) map.get("voucherid"));
        orderVoucherService.save(orderVoucher);

        log.info("保存订单成功");
    }
}
